#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef int ElemType;
int m; //m为操作次数
int length = 0; //双向链表的结点个数
typedef struct DuLNode {
    ElemType data; //数据域
    struct DuLNode *prior; //指向直接前驱
    struct DuLNode *next; //指向直接后继
}DuLNode, *DuLinkList;

void CreateDuList_R(DuLinkList &L, int n){ // 后插
    length = n;
    L = new DuLNode;
    L->prior = NULL;
    L->next = NULL;
    DuLNode *r = L;
    while(n--){
        DuLNode *p = new DuLNode;
        cin >> p->data;
        p->next = NULL;
        p->prior = r;
        r->next = p;
        r = p;
    }
    
}

DuLNode *GetElem_DuL(DuLinkList L, int i){
    if(i < 1 || i > length) return NULL;
    int j = 1;
    DuLNode *p = L->next;
    while(j < i && p){
        p = p->next;
        j++;
    }
    return p;
}

Status ListInsert_DuL(DuLinkList &L, int i, ElemType e){
    int j = 1;
    DuLNode *p = L;
    while(j < i && p->next){
        p = p->next;
        j++;
    }
    if(p){
        DuLNode *q = new DuLNode;
        q->data = e;
        q->next = p->next;
        q->prior = p;
        p->next->prior = q;
        p->next = q;
        return OK;
    }
    length++;
    return ERROR;
}

Status ListDelete_DuL(DuLinkList &L, int i){
    if(i < 1 || i > length) return ERROR;

    DuLNode *p = GetElem_DuL(L, i);
    if(!p) return ERROR;
    if(p->next){
        p->next->prior = p->prior;
        p->prior->next = p->next;
    }else{
        p->prior->next = NULL;
    }
    delete p;
    length--;
    return OK;
}

void Out_list(DuLinkList L){//输出双向链表
    DuLinkList p;
    p = L->next;
    while (p){
        cout <<p->data<<' ';
        p = p->next;
    }
    cout<<endl;
}

int main() {
    DuLinkList L,q;
    ElemType e;
    int i,temp,n;
    cin >> m;     //m次操作
    while(m --) {
        char op;
        cin >> op;
        switch(op){
            case 'C'://创建双向链表
                cin>>n;
                CreateDuList_R(L, n);
                Out_list(L);
                break;
            case 'S'://查找元素
                cin>>i;
                q = GetElem_DuL(L, i);
                if (q) {
                    cout<<q->data<<endl;
                }
                break;
            case 'I'://插入元素
                cin>>i;
                cin>>e;
                ListInsert_DuL(L, i, e);
                Out_list(L);
                break;
            case 'D'://删除元素
                cin>>i;
                ListDelete_DuL(L, i);
                Out_list(L);
                break;
        }
    }
    return 0;
}
